package com.noble.meether.fragment.mail;

import android.widget.ImageView;
import android.widget.TextView;

import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.library.widget.RecyclerView.base.BaseRecyclerViewAdapter;
import com.noble.library.widget.RecyclerView.base.BaseRecyclerViewHolder;
import com.noble.meether.R;
import com.noble.meether.chat.unread.UnreadMgrImpl;
import com.noble.meether.chat.unread.view.BadgeView;

/**
 * 信箱列表
 */
public class MailFragmentAdapter extends BaseRecyclerViewAdapter {
    private BadgeView friendBadge, noticeBadge;

    @Override
    public int[] getItemLayouts() {
        return new int[]{R.layout.mail_item_fragment};
    }

    @Override
    public void onBindRecycleViewHolder(BaseRecyclerViewHolder viewHolder, int position) {
        MailBean data = (MailBean) getItem(position);

        ImageView mail_icon = viewHolder.findViewById(R.id.mail_icon);
        TextView mail_title = viewHolder.findViewById(R.id.mail_title);
        TextView mail_content = viewHolder.findViewById(R.id.mail_content);
        TextView mail_time = viewHolder.findViewById(R.id.mail_time);
        BadgeView badgeView = viewHolder.findViewById(R.id.mail_number);

        mail_icon.setBackgroundResource(data.getRes());
        mail_title.setText(data.getName());

        // 好友列表
        if (position == 0) {
            friendBadge = badgeView;
            refreshRegister();
        }
        // 公告消息
        else if (position == 2) {
            noticeBadge = badgeView;
            refreshNoticeRegister();
        }
    }

    public void refreshBadge() {
        ModuleMgr.getUnreadMgr().onMsgNum(friendBadge, UnreadMgrImpl.MY_FRIEND);
        ModuleMgr.getUnreadMgr().onMsgNum(noticeBadge, UnreadMgrImpl.SYS_NOTICE);
    }

    public void refreshRegister() {
        ModuleMgr.getUnreadMgr().registerBadge(friendBadge, false, UnreadMgrImpl.MY_FRIEND);
    }

    public void refreshNoticeRegister() {
        ModuleMgr.getUnreadMgr().registerBadge(noticeBadge, false, UnreadMgrImpl.SYS_NOTICE);
    }

    @Override
    public int getRecycleViewItemType(int position) {
        return 0;
    }
}